**************************************************************
*** LISS: Combining individual and household data ***

*** LISS: combining all waves

**************************************************************

* Note: save all waves in one folder first

global CORE "SET_YOUR_INPUT_PATH\LISS\Core"
global ECON "SET_YOUR_INPUT_PATH\LISS\Economics - Income"
global POL "SET_YOUR_INPUT_PATH\LISS\Politics"
global SOC "SET_YOUR_INPUT_PATH\LISS\Social Integration and Leisure"
global OUT "SET_YOUR_OUTPUT_PATH\LISS"

*** combine core data
forval i=2008(1)2012 {
	use "$CORE\first\avars_`i'01_EN_2.0p.dta", clear
	isvar nomem_encr nohouse_encr geslacht positie gebjaar aantalhh belbezig nettoink nettohh_f oplmet oplcat herkomstgroep
	local OKlist "`r(varlist)'"
	keep `OKlist'
	
	rename nomem_encr pid
	rename nohouse_encr hhid
	rename geslacht sex_`i'
	rename positie hhpos_`i'
	rename gebjaar yob_`i'
	rename aantalhh hhsize_`i'
	rename belbezig empstat_`i'
	rename nettoink inc_`i'
	capture rename nettohh_f hhinc_`i'
	rename oplmet edu_`i'
	rename oplcat edu2_`i'
	capture rename herkomstgroep origin_`i'
	
	capture recode origin_`i' (0=0 "no migrant")(101/202=1 "migrant")(else=.), gen(mig_`i') 
	gen age_`i' = `i' - yob_`i' 

	save "$CORE\liss_core_`i'.dta", replace 
}

*2010: migration status (needs to be added separately)
use "$CORE\first\avars_201010_EN_2.0p.dta", clear
	isvar nomem_encr nohouse_encr herkomstgroep
	local OKlist "`r(varlist)'"
	keep `OKlist'
	
	rename nomem_encr pid
	rename nohouse_encr hhid
	rename herkomstgroep origin_2010
	
	capture recode origin_2010 (0=0 "no migrant")(101/202=1 "migrant")(else=.), gen(mig_2010) 

	save "$CORE\liss_core_2010_mig.dta", replace 


forval i=2013(1)2020 {
	use "$CORE\first\avars_`i'01_EN_1.0p.dta", clear
	keep nomem_encr nohouse_encr geslacht positie gebjaar aantalhh belbezig nettoink nettohh_f oplmet oplcat herkomstgroep
	rename nomem_encr pid
	rename nohouse_encr hhid
	rename geslacht sex_`i'
	rename positie hhpos_`i'
	rename gebjaar yob_`i'
	rename aantalhh hhsize_`i'
	rename belbezig empstat_`i'
	rename nettoink inc_`i'
	rename nettohh_f hhinc_`i'
	rename oplmet edu_`i'
	rename oplcat edu2_`i'
	capture rename herkomstgroep origin_`i'

	capture recode origin_`i' (0=0 "no migrant")(101/202=1 "migrant")(else=.), gen(mig_`i') 
	gen age_`i' = `i' - yob_`i' 

	save "$CORE\liss_core_`i'.dta", replace 
}

*merge
use "$CORE\liss_core_2008.dta", clear
merge 1:1 pid using "$CORE\liss_core_2009.dta", nogen
merge 1:1 pid using "$CORE\liss_core_2010.dta", nogen
merge 1:1 pid using "$CORE\liss_core_2010_mig.dta", nogen
merge 1:1 pid using "$CORE\liss_core_2011.dta", nogen
merge 1:1 pid using "$CORE\liss_core_2012.dta", nogen
merge 1:1 pid using "$CORE\liss_core_2013.dta", nogen
merge 1:1 pid using "$CORE\liss_core_2014.dta", nogen
merge 1:1 pid using "$CORE\liss_core_2015.dta", nogen
merge 1:1 pid using "$CORE\liss_core_2016.dta", nogen
merge 1:1 pid using "$CORE\liss_core_2017.dta", nogen
merge 1:1 pid using "$CORE\liss_core_2018.dta", nogen
merge 1:1 pid using "$CORE\liss_core_2019.dta", nogen
merge 1:1 pid using "$CORE\liss_core_2020.dta", nogen

fre mig*
gen migrant = .
replace migrant = mig_2010 if migrant==.
replace migrant = mig_2011 if migrant==.
replace migrant = mig_2012 if migrant==.
replace migrant = mig_2013 if migrant==.
replace migrant = mig_2014 if migrant==.
replace migrant = mig_2015 if migrant==.
replace migrant = mig_2016 if migrant==.
replace migrant = mig_2017 if migrant==.
replace migrant = mig_2018 if migrant==.
replace migrant = mig_2019 if migrant==.
replace migrant = mig_2020 if migrant==.

save "$CORE\liss_core.dta", replace



*** combine economic: income data
cd "$ECON"
local files : dir "$ECON" files "*.dta"

local i=2008
foreach file in `files' {
	use `file', clear
	keep nomem_encr *006
	rename nomem_encr pid
	rename *006 satfin_`i'
	save "./short/liss_econ_`i'.dta", replace
	local i=`i'+1
}

use "./short/liss_econ_2008.dta", clear
merge 1:1 pid using ".\short\liss_econ_2009.dta", nogen
merge 1:1 pid using ".\short\liss_econ_2010.dta", nogen
merge 1:1 pid using ".\short\liss_econ_2011.dta", nogen
merge 1:1 pid using ".\short\liss_econ_2012.dta", nogen
merge 1:1 pid using ".\short\liss_econ_2013.dta", nogen
merge 1:1 pid using ".\short\liss_econ_2014.dta", nogen
merge 1:1 pid using ".\short\liss_econ_2015.dta", nogen
merge 1:1 pid using ".\short\liss_econ_2016.dta", nogen
merge 1:1 pid using ".\short\liss_econ_2017.dta", nogen
merge 1:1 pid using ".\short\liss_econ_2018.dta", nogen
merge 1:1 pid using ".\short\liss_econ_2019.dta", nogen

save "./short/liss_econ.dta", replace



*** combine social integration data
cd "$SOC"
local files : dir "$SOC" files "*.dta"

local i=2008
foreach file in `files' {
	use `file', clear
	keep nomem_encr *043 *044 *045 *046 *047 
	rename nomem_encr pid
	rename *043 party1_`i'
	rename *044 party2_`i'
	rename *045 party3_`i'
	rename *046 party4_`i'
	rename *047 party5_`i'
	save "./short/liss_soc_`i'.dta", replace
	local i=`i'+1
}

use "./short/liss_soc_2008.dta", clear
merge 1:1 pid using ".\short\liss_soc_2009.dta", nogen
merge 1:1 pid using ".\short\liss_soc_2010.dta", nogen
merge 1:1 pid using ".\short\liss_soc_2011.dta", nogen
merge 1:1 pid using ".\short\liss_soc_2012.dta", nogen
merge 1:1 pid using ".\short\liss_soc_2013.dta", nogen
merge 1:1 pid using ".\short\liss_soc_2014.dta", nogen
merge 1:1 pid using ".\short\liss_soc_2015.dta", nogen
merge 1:1 pid using ".\short\liss_soc_2016.dta", nogen
merge 1:1 pid using ".\short\liss_soc_2017.dta", nogen
merge 1:1 pid using ".\short\liss_soc_2018.dta", nogen

save "./short/liss_soc.dta", replace




*combine politics data
cd "$POL"
local files : dir "$POL" files "*.dta"

local i=2008
foreach file in `files' {
	use `file', clear
	isvar nomem_encr *001 *002 *003 *004 *005 *006 *007 *008 /// 
	?????009 *010 *011 *012 *013 *014 *015 *016 *017 *018 ///
	?????019 *020 *021 *022 *023 *024 *025 *026 *027 *028 *029 ///
	?????030 *031 *032 *033 *034 *035 *036 *037 *038 *039 *040 ///
	?????041 *042 *043 *044 *045 *046 *047 *048 *049 *050 *051 ///
	?????052 *053 *058 *060 *061 *062 *063 *064 *065 *066 *067 ///
	?????068 *069 *070 *071 *072  ///
	cv11d171 cv12e171 cv13f209 cv14g209 cv16h209 cv17i244 cv18j308 cv19k308 cv20l308 ///   
	cv17i243 cv18j243 cv19k243 cv20l243 ///
	
	local OKlist "`r(varlist)'"
	keep `OKlist'
	
	capture rename nomem_encr pid
	capture rename ?????001 satgov_now_`i'
	capture rename ?????002 news_tvr_`i'
	capture rename ?????003 news_inet_`i'
	capture rename ?????004 news_paper1_`i'
	capture rename ?????005 news_paper2_`i'
	capture rename ?????006 news_not_`i'
	capture rename ?????007 news_dk_`i'
	capture rename ?????008 news_interest_`i'
	capture rename ?????009 news_read1_`i'
	capture rename ?????010 news_read2_`i'
	capture rename ?????011 news_read3_`i'
	capture rename ?????012 polint_`i'
	capture rename ?????013 conf_gov_`i'
	capture rename ?????014 conf_parl_`i'
	capture rename ?????015 conf_legal_`i'
	capture rename ?????016 conf_police_`i'
	capture rename ?????017 conf_polit_`i'
	capture rename ?????018 conf_parties_`i'
	capture rename ?????019 conf_euparl_`i'
	capture rename ?????020 conf_un_`i'
	capture rename ?????021 conf_media_`i'
	capture rename ?????022 conf_mil_`i'
	capture rename ?????023 conf_edu_`i'
	capture rename ?????024 conf_health_`i'
	capture rename ?????025 conf_science_`i'
	capture rename ?????026 conf_econ_`i'
	capture rename ?????027 conf_demo_`i'
	capture rename ?????028 conf_shops1_`i'
	capture rename ?????029 conf_shops2_`i'
	capture rename ?????030 sat_gov_`i'
	capture rename ?????031 sat_parl_`i'
	capture rename ?????032 sat_legal_`i'
	capture rename ?????033 sat_police_`i'
	capture rename ?????034 sat_polit_`i'
	capture rename ?????035 sat_parties_`i'
	capture rename ?????036 sat_euparl_`i'
	capture rename ?????037 sat_un_`i'
	capture rename ?????038 sat_media_`i'
	capture rename ?????039 sat_mil_`i'
	capture rename ?????040 sat_edu_`i'
	capture rename ?????041 sat_health_`i'
	capture rename ?????042 sat_science_`i'
	capture rename ?????043 sat_econ_`i'
	capture rename ?????044 sat_demo_`i'
	capture rename ?????045 sat_shops1_`i'
	capture rename ?????046 sat_shops2_`i'
	capture recode ?????047 (1=0 "no effex")(2=1 "high effex"), gen(effex1_`i')
	capture recode ?????048 (1=0 "no effex")(2=1 "high effex"), gen(effex2_`i')
	capture recode ?????049 (1=0 "no effex")(2=1 "high effex"), gen(effex3_`i')
	capture recode ?????050 (2=0 "no effex")(1=1 "high effex"), gen(effint1_`i')
	capture recode ?????051 (2=0 "no effex")(1=1 "high effex"), gen(effint2_`i')
	capture recode ?????052 (1=0 "no effex")(2=1 "high effex"), gen(effint3_`i')
	capture egen effex_`i' = anycount(effex1_`i' effex2_`i' effex3_`i'), val(1)
	capture egen effint_`i' = anycount(effint1_`i' effint2_`i' effint3_`i'), val(1)
	lab var effint_`i' "Internal Efficacy Index `i'"
	lab var effex_`i' "External Efficacy Index `i'"
	capture recode ?????053 (1=1 "yes")(2 99=0 "no")(else=.), gen(vote_retro_`i')
	capture recode ?????058 (3/14=1 "yes")(1 15=0 "no")(else=.), gen(vote_next_`i')
	capture recode ?????171 (3/14=1 "yes")(1 15=0 "no")(else=.), gen(vote_next_`i')
	capture recode ?????209 (3/14=1 "yes")(1 15=0 "no")(else=.), gen(vote_next_`i')
	capture recode ?????244 (3/14=1 "yes")(1 15=0 "no")(else=.), gen(vote_next_`i')
	capture recode ?????308 (3/14=1 "yes")(1 15=0 "no")(else=.), gen(vote_next_`i')
	capture recode ?????243 (101/999=.), gen(voteintent_`i')
	capture rename ?????060 vote_conf1_`i'
	capture rename ?????061 vote_conf2_`i'
	capture rename ?????062 vote_conf3_`i'
	capture rename ?????063 vote_conf4_`i'
	capture rename ?????064 vote_conf5_`i'
	capture rename ?????065 part1_`i'
	capture rename ?????066 part2_`i'
	capture rename ?????067 part3_`i'
	capture rename ?????068 part4_`i'
	capture rename ?????069 part5_`i'
	capture rename ?????070 part6_`i'
	capture rename ?????071 part7_`i'
	capture rename ?????072 part8_`i'
	egen part_`i' = anycount(part1_`i'-part8_`i'), val(1)
	lab var part_`i' "Political Participation Index `i'"
	
	drop ?????047 ?????048 ?????049 ?????050 ?????051 ?????052 ?????053 
	capture drop ?????058
	save "./short/liss_pol_`i'.dta", replace
	local i=`i'+1
}

use "./short/liss_pol_2008.dta", clear
merge 1:1 pid using ".\short\liss_pol_2009.dta", nogen
merge 1:1 pid using ".\short\liss_pol_2010.dta", nogen
merge 1:1 pid using ".\short\liss_pol_2011.dta", nogen
merge 1:1 pid using ".\short\liss_pol_2012.dta", nogen
merge 1:1 pid using ".\short\liss_pol_2013.dta", nogen
merge 1:1 pid using ".\short\liss_pol_2014.dta", nogen
merge 1:1 pid using ".\short\liss_pol_2015.dta", nogen
merge 1:1 pid using ".\short\liss_pol_2016.dta", nogen
merge 1:1 pid using ".\short\liss_pol_2017.dta", nogen
merge 1:1 pid using ".\short\liss_pol_2018.dta", nogen

save "./short/liss_pol.dta", replace





**************
* Merge all 
**************

use "$CORE\liss_core.dta", clear
merge 1:1 pid using "$ECON\short\liss_econ.dta", nogen
merge 1:1 pid using "$SOC\short\liss_soc.dta", nogen
merge 1:1 pid using "$POL\short\liss_pol.dta", nogen


*reshape to long format
reshape long age_ conf_demo_ conf_econ_ conf_edu_ conf_euparl_ conf_gov_ conf_health_ conf_legal_ ///
conf_media_ conf_mil_ conf_parl_ conf_parties_ conf_police_ conf_polit_ conf_science_ ///
conf_shops1_ conf_shops2_ conf_un_ edu_ edu2_ effex1_ effex2_ effex3_ effex_ effint1_ ///
effint2_ effint3_ effint_ empstat_ hhpos_ hhsize_ inc_ hhinc_ news_dk_ news_inet_ news_interest_ ///
news_not_ news_paper1_ news_paper2_ news_read1_ news_read2_ news_read3_ news_tvr_ part1_ part2_ ///
part3_ part4_ part5_ part6_ part7_ part8_ part_ party1_ party2_ party3_ party4_ party5_ ///
polint_ sat_demo_ sat_econ_ sat_edu_ sat_euparl_ sat_gov_ sat_health_ sat_legal_ ///
sat_media_ sat_mil_ sat_parl_ sat_parties_ sat_police_ sat_polit_ sat_science_ ///
sat_shops1_ sat_shops2_ sat_un_ satfin_ satgov_now_ sex_ vote_conf1_ vote_conf2_ ///
vote_conf3_ vote_conf4_ vote_conf5_ vote_next_ voteintent_ vote_retro_ yob_ , i(pid) j(year)

rename *_ *

***recoding

rename polint interest
recode interest (1=3 "very interested")(2=2 "fairly interested")(3=1 "not interested")(else=.), gen(polint)
drop interest
lab var polint "Political Interest"

egen party_sup = anycount(party2 party3 party4 party5), val(1)
replace party_sup=. if party2==. & party3==. & party4==. & party5==.
replace party_sup=0 if party1==1
lab var party_sup "Degree of party support"


mvdecode satfin sat_gov conf_gov, mv(-9 999)
mvdecode hhsize, mv(10/15)

*sep
drop if hhinc>100000 & hhinc<300000	// drop really high income>100000 per month (n=75)
gen hhinc_pp = hhinc/hhsize
gen hhinc_pp_sqrt = hhinc/(sqrt(hhsize))

xtile hhinc_dec = hhinc, nq(10) 
xtile hhinc_dec_pp = hhinc_pp, nq(10) 
xtile hhinc_dec_pp_sqrt = hhinc_pp_sqrt, nq(10) 

gen hhinc_dec10 = (hhinc_dec-1)*(10/9)
gen hhinc_dec_pp10 = (hhinc_dec_pp-1)*(10/9)
gen hhinc_dec_pp_sqrt10 = (hhinc_dec_pp_sqrt-1)*(10/9)


//satfin
fre satfin
clonevar hhinc_sat10 = satfin


*political variables 
fre vote_next vote_retro party_sup effint effex part satgov_now sat_gov conf_gov
//polint
recode polint (2 3=1 "interested")(1=0 "not interested")(else=.), gen(polint01)

//recode 0-10
gen voteintent10 = (voteintent)/(10)
gen party_sup10 = (party_sup)*(10/4)
gen effint10 = (effint)*(10/3)
gen effex10 = (effex)*(10/3)
gen part10 = (part)*(10/8)
gen satgov_now10 = (satgov_now-1)*(10/4)
clonevar sat_gov10 = sat_gov
clonevar conf_gov10 = conf_gov

fre party_sup10 effint10 effex10 part10 satgov_now10 sat_gov10 conf_gov10


*socio-demographics
recode sex (1=0 "male")(2=1 "female"), gen(female)
fre empstat
recode empstat (4 5 6  11=1 "unemployed")(1/3 7/10 12/14=0 "other")(else=.), gen(unemployed)
recode empstat (7/10 12/14=1 "not in labor force")(1/6 11=0 "other"), gen(nlf)

recode edu (1 2=1 "low")(3/6=0 "other")(else=.), gen(edu_low)
recode edu (3 4=1 "medium")(1 2 5 6=0 "other")(else=.), gen(edu_med)
recode edu (5 6=1 "high")(1/4=0 "other")(else=.), gen(edu_high)

recode age (13/25=1)(26/120=0)(else=.), gen(age1825)
recode age (13/35=1)(36/120=0)(else=.), gen(age1835)

gen age18 = age-18

*fre origin

*create interaction variables
gen hhinc_decXage = hhinc_dec10 * age18
gen hhinc_dec_ppXage = hhinc_dec_pp10 * age18
gen hhinc_dec_pp_sqrtXage = hhinc_dec_pp_sqrt10 * age18
gen hhinc_satXage = hhinc_sat10 * age18

gen hhinc_decXage1825 = hhinc_dec10 * age1825
gen hhinc_satXage1825 = hhinc_sat10 * age1825

gen hhinc_decXage1835 = hhinc_dec10 * age1835
gen hhinc_satXage1835 = hhinc_sat10 * age1835





*save
save "$OUT\liss_long.dta", replace

 


